/*
 *  Copyright 2005 Blandware (http://www.blandware.com)
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */
package com.blandware.atleap.model.questionnaire;

import com.blandware.atleap.model.core.BaseObject;

import java.util.Date;
import java.util.List;
import java.util.ArrayList;

/**
 * <p>Represents a filled questionnaire.</p>
 * <p><a href="FilledQuestionnaire.java.html"><i>View source</i></a></p>
 *
 * @author Roman Puchkovskiy <a href="mailto:roman.puchkovskiy@blandware.com">
 *         &lt;roman.puchkovskiy@blandware.com&gt;</a>
 * @version $Revision: 1.3 $ $Date: 2006/06/15 10:52:36 $
 * @struts.form include-all="false" extends="BaseForm"
 * @hibernate.class table="`al_questionnaire_filled`" lazy="false"
 */
public class FilledQuestionnaire extends BaseObject {

    /**
     * ID
     */
    protected Long id;

    /**
     * Questionnaire which is filled
     */
    protected Questionnaire questionnaire;

    /**
     * Date when questionnaire was filled
     */
    protected Date date;

    /**
     * List of answers to questionnaire
     */
    protected List answers = new ArrayList();

    /**
     * Returns ID.
     *
     * @return ID
     * @struts.form-field
	 * @hibernate.id column="`id`"
	 * generator-class="increment" unsaved-value="null"
     */
    public Long getId() {
        return id;
    }

    /**
     * Sets ID.
     *
     * @param id ID to set
     */
    public void setId(Long id) {
        this.id = id;
    }

    /**
     * Returns a questionnaire.
     *
     * @return questionnaire
     * @struts.form-field
	 * @hibernate.many-to-one column="`questionnaire_id`" not-null="true"
     * outer-join="false" lazy="false"
     */
    public Questionnaire getQuestionnaire() {
        return questionnaire;
    }

    /**
     * Sets a questionnaire.
     *
     * @param questionnaire questionnaire to set
     */
    public void setQuestionnaire(Questionnaire questionnaire) {
        this.questionnaire = questionnaire;
    }

    /**
     * Returns date.
     *
     * @return date
     * @hibernate.property type="timestamp"
	 * @hibernate.column name="`date`"  not-null="true"
     * unique="false"
     */
    public Date getDate() {
        return date;
    }

    /**
     * Sets date.
     *
     * @param date date to set
     */
    public void setDate(Date date) {
        this.date = date;
    }

    /**
     * Returns list of answers.
     *
     * @return list of answers
     * @hibernate.bag name="answers" inverse="true" lazy="true"
     * cascade="all" outer-join="false"
	 * @hibernate.collection-key column="`f_questionnaire_id`"
	 * @hibernate.collection-one-to-many class="com.blandware.atleap.model.questionnaire.Answer"
     */
    public List getAnswers() {
        return answers;
    }

    /**
     * Sets list of answers.
     *
     * @param answers list to set
     */
    public void setAnswers(List answers) {
        this.answers = answers;
    }

    /**
     * Adds answer to this filled quetionnaire.
     *
     * @param answer the answer to be added
     */
	public void addAnswer(Answer answer) {
		answer.setFilledQuestionnaire(this);
		answers.add(answer);
	}

    /**
     * Removes answer from this filled questionnaire.
     *
     * @param answer the answer to be removed
     */
	public void removeAnswer(FilledQuestionnaire answer) {
		answers.remove(answer);
	}

    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (!(o instanceof FilledQuestionnaire)) {
            return false;
        }

        final FilledQuestionnaire filledQuestionnaire = (FilledQuestionnaire) o;

        if (date != null
                ? !date.equals(filledQuestionnaire.date)
                : filledQuestionnaire.date != null) {
            return false;
        }
        if (questionnaire != null
                ? !questionnaire.equals(filledQuestionnaire.questionnaire)
                : filledQuestionnaire.questionnaire != null) {
            return false;
        }

        return true;
    }

    public int hashCode() {
        int result;
        result = (questionnaire != null ? questionnaire.hashCode() : 0);
        result = 29 * result + (date != null ? date.hashCode() : 0);
        return result;
    }
}
